package com.hhsj.glidesource.factoryMethod;

public class Test {
    public static void main(String[] args) {
        Client client = new Client();
        client.create(1);
        client.create(2);
        client.create(3);
    }
}


interface Food {

    void cook();
}

class A implements Food {

    @Override
    public void cook() {
        System.out.println("A cook");
    }
}

class B implements Food {

    @Override
    public void cook() {
        System.out.println("B cook");
    }
}

class C implements Food {
    @Override
    public void cook() {
        System.out.println("C cook");
    }
}

class FoodFactory {
    private FoodFactory() {
    }

    public static Food getA() {
        return new A();
    }

    public static Food getB() {
        return new B();
    }

    public static Food getC() {
        return new C();
    }
}

class Client {
    public void create(int type) {
        Food food = null;
        switch (type) {
            case 1:
                food = FoodFactory.getA();
                break;
            case 2:
                food = FoodFactory.getB();
                break;
            case 3:
                food = FoodFactory.getC();
                break;
        }
        // TODO: 2018/11/15 do shao

        if (food != null) {
            food.cook();
        }
    }
}

